<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("platinumgrid/jtplatinumgrid.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class frame_tire_list extends Page
{
       public $btnSearch = null;
       public $edtSearch = null;
       public $Image4 = null;
       public $edit = null;
       public $delete = null;
       public $imgAdd = null;
       public $hfFirstCtr = null;
       public $hfFirstTireId = null;
       public $showTireAjax = null;
       public $hfSearch = null;
       public $JTSiteTheme1 = null;
       public $JTGridTires = null;
       function edtSearchJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('edtSearch').value='';
       <?php

       }

       function imgAddJSClick($sender, $params)
       {

       ?>
       //var height = 270;
       var height = 350;
       //var width = 670;
       var width = 750;
       var left = Math.floor((screen.availWidth/2) - (width/2));
       var top = Math.floor((screen.availHeight/2) - (height/2));
       window.open('pop_tire_create.php', 'tire_create','width='+width+',height='+height+',top='+top+',left='+left);
       <?php

       }

       function imgAddJSMouseOver($sender, $params)
       {

       ?>
       document.images['imgAdd'].src="image/add_new_blue.png"
       <?php

       }

       function imgAddJSMouseOut($sender, $params)
       {

       ?>
       document.images['imgAdd'].src="image/add_new.png"
       <?php

       }

       function JTGridTiresJSDataLoad($sender, $params)
       {

       ?>
       var ctr = document.getElementById('hfFirstCtr').value;
       if(ctr==0)
       {
       var firstTireId = document.getElementById('hfFirstTireId').value;
       showTire(firstTireId);
       }
       document.getElementById('hfFirstCtr').value = ctr + 1;
       <?php

       }

       function frame_tire_listCreate($sender, $params)
       {
       $this->hfFirstCtr->setValue(0);
       $search = $_GET['search'];
       if($search!=null || $search!='')
       {
       $this->hfSearch->setValue($search);
       $this->edtSearch->setText($search);
       }
       else
       {
       $this->edtSearch->Text = '';
       $this->hfSearch->setValue('');
       }

       if($_SESSION['access_vehicle']==1)
       {
       $this->imgAdd->Visible=false;
       }

       if($_SESSION['access_vehicle']==2)
       {
       $this->imgAdd->Visible=true;
       }

       }
       function btnSearchJSClick($sender, $params)
       {

       ?>
       var search = document.getElementById('edtSearch').value;
       document.location.href = "frame_tire_list.php?search="+search;
       <?php

       }

       function JTGridTiresShow($sender, $params)
       {
       $company_id = $_SESSION['company_id'];
       $arr_tires = array();
       $search = $this->hfSearch->getValue();
       $query_tires = "SELECT * FROM tire_inventory_tbl
       WHERE status='0'
       AND company_id='".$company_id."'
       AND (tire_SN LIKE '%".$search."%'
       OR manufacturer LIKE '%".$search."%'
       OR size LIKE '%".$search."%'
       OR type LIKE '%".$search."%'
       OR purch_date LIKE '%".$search."%')
       ORDER BY tire_id";
       $result_tires = mysql_query($query_tires) or die("TIRES ".mysql_error());

       $ctr_tire = 0;
       while($row_tires = mysql_fetch_array($result_tires))
       {
        if($ctr_tire==0)
        {

        //$tire_sn_radio = "<input type='radio' name='radio_tire_id' onclick=document.getElementById('hiddenTireIdSave').value=".$row_tires['tire_id']." checked/> ".$row_tires['tire_sn'];
        $tire_sn_radio = "<input type='radio' name='radio_tire_id' onchange='showTire(".$row_tires['tire_id'].")' checked/> <span onclick='editTire(".$row_tires['tire_id'].")' style='color:blue;text-decoration:underline;cursor:pointer'>".$row_tires['tire_SN']."</span>";

        $this->hfFirstTireId->setValue($row_tires['tire_id']);
        //$this->hiddenTireIdSave->setValue($row_tires['tire_id']);
        //$this->hfDescTireSn->setValue($row_tires['tire_SN']);
        }
        if($ctr_tire!=0)
        {
        //$tire_sn_radio = "<input type='radio' name='radio_tire_id' onclick=document.getElementById('hiddenTireIdSave').value=".$row_tires['tire_id']."> ".$row_tires['tire_sn'];
        $tire_sn_radio = "<input type='radio' name='radio_tire_id' onchange='showTire(".$row_tires['tire_id'].")')> <span onclick='editTire(".$row_tires['tire_id'].")' style='color:blue;text-decoration:underline;cursor:pointer'>".$row_tires['tire_SN']."</span>";
        }
        $delete = "<img onclick=js_delete('".$row_tires['tire_id']."','".$search."'); src='image/delete.png' title='delete' style='cursor:pointer' />";

        if($_SESSION['access_vehicle']==1)
        {
        $arr_tires[] = array('Tire ID'=>$tire_sn_radio,
        'Brand'=>$row_tires['manufacturer'],
        'Size'=>$row_tires['size'],
        'Type'=>$row_tires['type'],
        'Date Purchased'=>$row_tires['purch_date']);
        }

        if($_SESSION['access_vehicle']==2)
        {
        $arr_tires[] = array('Tire ID'=>$tire_sn_radio,
        'Brand'=>$row_tires['manufacturer'],
        'Size'=>$row_tires['size'],
        'Type'=>$row_tires['type'],
        'Date Purchased'=>$row_tires['purch_date'],
        'Tools'=>$delete);
        }

        $ctr_tire++;
       }
       $this->JTGridTires->setCellData($arr_tires);
       }
}

global $application;

global $frame_tire_list;

//Creates the form
$frame_tire_list=new frame_tire_list($application);

//Read from resource file
$frame_tire_list->loadResource(__FILE__);

//Shows the form
$frame_tire_list->show();

?>